package cuid.sc20.laboratory.config;

import cuid.sc20.laboratory.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {
    private LoginInterceptor loginInterceptor;
    @Autowired
    public void setLoginInterceptor(LoginInterceptor loginInterceptor) {
        this.loginInterceptor = loginInterceptor;
    }
    /**
     * 向系统注册一个拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //-- /**  拦截所有请求
        registry
                .addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/","index.html","/login/goToLogin","login.html");
    }
}
